package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.TeacherService;
import com.wanxi.vo.TeacherVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/teacher")
@CrossOrigin(origins = "http://localhost:8081")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('insertTeacher')")
    public ResultDTO addTeacher(TeacherVO teacherVO){
        return teacherService.addTeacher(teacherVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteTeacher')")
    public ResultDTO deleteTeacher(TeacherVO teacherVO){
        return teacherService.delete(teacherVO);
    }

    @GetMapping("/findAll")
    public ResultDTO findAllTeacher(){
        return teacherService.findAllTeacher();
    }

    @PostMapping("/findById")
    public ResultDTO findTeacherById(TeacherVO teacherVO){
        return teacherService.findTeacherById(teacherVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateTeacher')")
    public ResultDTO updateTeacherEnable(TeacherVO teacherVO){
        return teacherService.updateEnable(teacherVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateTeacher')")
    public ResultDTO updateTeacher(TeacherVO teacherVO){
        return teacherService.update(teacherVO);
    }
}
